package rabbit.ding;

import com.rabbitmq.client.Channel;
import rabbit.util.RabbitMqUtils;

import java.io.IOException;
import java.util.Scanner;
import java.util.concurrent.TimeoutException;

/**
 * Created with IntelliJ IDEA.
 * ClassName: EmitLog
 * Package: rabbit.ding
 * Description:
 * User: fzykd
 *
 * @Author: LQH
 * Date: 2023-10-25
 * Time: 21:51
 */

public class EmitLog {

    //发消息 到 交换机
    public static final String EXCHANGE_NAME = "logs";

    public static void main(String[] args) throws IOException, TimeoutException {
        Channel chanel = RabbitMqUtils.getChanel();
        chanel.exchangeDeclare(EXCHANGE_NAME,"fanout");
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()){
            String message = scanner.next();
            //交换机 Key 其他参数 消息体
            chanel.basicPublish(EXCHANGE_NAME,"",null,message.getBytes());
            System.out.println("成功发送: " + message);
        }

    }

}
